package xiaodou.services
{
	import mx.utils.StringUtil;
	
	import xiaodou.data.account.UserData;
	import xiaodou.data.blogAccount.BlogAccountData;
	
	public class APIConfig
	{	
		private static var _rootUrl:String;
		public static function init(rootUrl:String):void
		{
			_rootUrl = rootUrl;
		}
		
		private static function get rootUrl():String
		{
			return _rootUrl;
		}
		
		/**
		 * 登录链接 
		 * @param name 登录名
		 * @param password 密码
		 * @return 
		 * 
		 */		
		public static function createLoginUrl(name:String, password:String):String
		{
			
			return rootUrl + StringUtil.substitute("account/control.ashx?type={0}&account={1}&password={2}",
				5, name, password);
		}
		
		/**
		 * 获取所有帐号列表 
		 * @return 
		 * 
		 */		
		public static function get ALL_ACCOUNT_LIST():String
		{
			return rootUrl + "account/AccountListAshx.ashx";
		}
		
		/**
		 * 帐号更新
		 * 
		 */		
		public static function createAccountUpdateUrl(account:UserData):String
		{
			return rootUrl + StringUtil.substitute("account/control.ashx?type={0}&id={1}&account={2}&password={3}&access={4}",
				4, account.id, account.name, account.password, account.access);
		}
		
		/**
		 * 帐号删除 
		 * @param id 帐号ID
		 * @return 
		 * 
		 */		
		public static function createAccountDeleteUrl(id:int):String
		{
			return rootUrl + StringUtil.substitute("account/control.ashx?type={0}&id={1}", 2, id);
		}
		
		/**
		 * 帐号添加 
		 * @param account
		 * @return 
		 * 
		 */		
		public static function createAccountAddUrl(account:UserData):String
		{
			return rootUrl + StringUtil.substitute("account/control.ashx?type={0}&account={1}&password={2}&access={3}", 1, account.name, account.password, account.access);
		}
		
		/**
		 * 更新关联的微博 
		 * @param userId
		 * @param blogAccountStr
		 * @return 
		 * 
		 */		
		public static function updateBlogAccountMapUrl(userId:int, blogAccountStr:String):String
		{
			return rootUrl + StringUtil.substitute("account/control.ashx?type={0}&id={1}&blogAccount={2}", 6, userId, blogAccountStr);
		}
		
		/**
		 * 获取重点粉丝列表 
		 * @return 
		 * 
		 */		
		public static function createInitImportantFansUrl(weiboId:String):String
		{
			return rootUrl + "importantFans/control.ashx?type=3&weiboId=" + weiboId;
		}
		
		/**
		 * 添加重点粉丝 
		 * @param id
		 * @return 
		 * 
		 */		
		public static function addImportantFansUrl(weiboId:String, fansId:String):String
		{
			return rootUrl + StringUtil.substitute("importantFans/control.ashx?type=1&weiboId={0}&fansId={1}", weiboId, fansId);
		}
		
		/**
		 * 删除重点粉丝 
		 * @param id
		 * @return 
		 * 
		 */		
		public static function removeImportantFansUrl(weiboId:String, fansId:String):String
		{
			return rootUrl + StringUtil.substitute("importantFans/control.ashx?type=2&weiboId={0}&fansId={1}", weiboId, fansId);
		}
		
		/**
		 * 获取所有微博帐号列表 
		 * 
		 */		
		public static function createSelectBlogAccountListUrl():String
		{
			return rootUrl + StringUtil.substitute("blogAccount/control.ashx?type={0}", 4);
		}
		
		/**
		 * 删除微博帐号 
		 * @param blogAccountId
		 * @return 
		 * 
		 */		
		public static function createDeleteBlogAccount(blogAccountId:int):String
		{
			return rootUrl + StringUtil.substitute("blogAccount/control.ashx?type={0}&blogAccountId={1}", 2, blogAccountId); 
		}
		
		/**
		 * 添加要定时回复的微博 
		 * @param weiboId 原始微博ID
		 * @param reply 回复内容
		 * @param useToken 使用的KEY，这里不使用微博ID,是防止微博被删除后，取不到TOKEN
		 * @param replyTime 指定的回复时间
		 * @param commentId 评论ID，如果回复的评论，此参数有值
		 * @return 
		 * 
		 */		
		public static function createDelayReply(weiboId:String, reply:String, useToken:String, replyTime:Date, commentId:String):String
		{
			return encodeURI(rootUrl + StringUtil.substitute("delaySendWeibo/control.ashx?type=1&weiboId={0}&reply={1}&replyAccount={2}&replyTime={3}&commentId={4}", weiboId, reply, useToken, replyTime.time, commentId));
		}
		
		
		public static function dealSelectList():String
		{
			return rootUrl + "dealWeibo/control.ashx?type=2";
		}
		public static function dealWeiboUpdateStatus(weiboId:String, status:int):String
		{
			return rootUrl + StringUtil.substitute("dealWeibo/control.ashx?type=1&weiboId={0}&status={1}", weiboId, status);
		}
		
		public static function addBlogAccount(blogAccount:BlogAccountData):String
		{
			return encodeURI(rootUrl + StringUtil.substitute("blogAccount/control.ashx?type=1&account={0}&des={1}&accessToken={2}&expireIn={3}", blogAccount.account, blogAccount.des, blogAccount.accessToken, blogAccount.expireIn.time));
		}
		
		public static function delayNewWeiboList():String
		{
			return encodeURI(rootUrl + "delaySendWeibo/control.ashx?type=3");
			
		}
		
		public static function delayNewWeiboDelete(id:int):String
		{
			return encodeURI(rootUrl + StringUtil.substitute("delaySendWeibo/control.ashx?type=2&id={0}", id));
		}
		
		public static function delayWeiboUpdate(id:int, newReply:String):String
		{
			return encodeURI(rootUrl + StringUtil.substitute("delaySendWeibo/control.ashx?type=4&id={0}&reply={1}", id, newReply));
		}
		
		public static function gatherInfo(account:String):String
		{
			return encodeURI(rootUrl + StringUtil.substitute("getUserCountInfo/control.ashx?account={0}", account));
		}
	}
}